﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="contact-list.aspx.cs" Inherits="VQWEB.administrator.contact.contact_list" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
   <div class="table-responsive">       
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
      <script type="text/javascript">
          ShowToolBar("add");
          var url_ashx = "/admin/contact/handler";
          var url_list = '<%=ResolveUrl("~/administrator/templates/list.tpl") %>';
          $(document).ready(function () {
              $.get(url_ashx, { list_contact: "list_contact" }, function (data) {
                  list(data);
              });
          });

          $(document).on("click", "#btnAdd", function () {
              window.location = "/admin/contact/add";
          });

          $(document).on("click", "#btnEdit", function () {
              var Id = $("input[name='chkItem']:checked").first().attr("value");
              if (Id != undefined)
                  window.location = "/admin/contact/edit/" + Id;
          });
          //LockUnLock
          $(document).on("click", "#btnLockUnlock", function () {
              var array = InputChecked();
              if (array.length > 0) {
                  $.post(url_ashx, { lockunlock_contact: JSON.stringify(array) }, function (data) {
                      list(data);
                  });
              }
          });
          //Delete
          $(document).on("click", "#btnDelete", function (e) {
              var array = InputChecked();
              if (array.length > 0) {
                  if (confirm("Bạn muốn xóa bản ghi không ???")) {
                      $.post(url_ashx, { delete_contact: JSON.stringify(array) }, function (data) {
                          list(data);
                      });
                  }
              }

          });

          //List
          function list(data) {
              var plusData = $.parseJSON(data);
              var columns = ["STT", "<input name='chkAll' value='' type='checkbox'>", "Full Name", "Address", "Active"];
              var rows = new Array();
              $.each(plusData, function (i, obj) {
                  var row = [];
                  var active = (obj.active) ? "Kích hoạt" : "Chưa kích hoạt";
                  var url = "<a href=/admin/contact/view/" + obj.id + ">" + obj.fullname + "</a>";
                  var checkbox = "<input name='chkItem' type='checkbox'  value=" + obj.id + ">";
                  row.push(i + 1);
                  row.push(checkbox);
                  row.push(url);
                  row.push(obj.address);
                  row.push(active);
                  rows.push(row);
              });
              $('div.table-responsive').empty();
              $.jqoteload(url_list, function (templates) {
                  $('div.table-responsive').jqoteapp(templates.list_tpl, { columns: columns, rows: rows });
              });
          }
    </script>
</asp:Content>
